package prv.pursuivant.util;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

public class DateUtil {

	/**
	 * Parses date from wow-armory xml files.
	 */
	public Date parseWowDate(String source) {
		// TODO: ugly as hell, need to be DateFormat-derived
		int y = Integer.valueOf(source.substring(0, 4));
		int m = Integer.valueOf(source.substring(5, 7));
		int d = Integer.valueOf(source.substring(8, 10));
		return createDate(y, m, d);
	}

	/**
	 * @param year
	 * @param month
	 * @param day
	 * @return Date with given parameters
	 */
	public Date createDate(int year, int month, int day) {
		Calendar cal = Calendar.getInstance();
		cal.clear();
		cal.set(year, month - 1, day);
		return cal.getTime();
	}

	// TODO: i18n this
	private final DateFormat format = new SimpleDateFormat("yyyy-MM-dd");
	private final DateFormat formatShort = new SimpleDateFormat("yy-MM-dd");

	/**
	 * 
	 * @param date
	 * @return
	 */
	public String format(Date date) {
		return format.format(date);
	}

	public String formatShort(Date date) {
		return formatShort.format(date);
	}

}
